package com.repast.service.impl;

import java.util.List;

import com.repast.common.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.repast.common.ServerResponse;
import com.repast.dao.FoodsMapper;
import com.repast.pojo.Foods;
import com.repast.service.IFoodsService;

@Service
public class FoodsServiceImpl implements IFoodsService{
	
	@Autowired
	private FoodsMapper foodsMapper;
	
	public ServerResponse selectFoodsList(Integer pageNum,Integer pageSize) {
		PageHelper.startPage(pageNum,pageSize);
		//只查询上架的商品
		List<Foods> list = foodsMapper.selectGoodsList(Const.FoodsStatus.FOODS_SHANGJIA);
		if(list.size()==0){
			return ServerResponse.createByErrorMessage("当前还没有数据");
		}
		PageInfo pageInfo = new PageInfo(list);
		return ServerResponse.createBySuccess(pageInfo);
	}
	
	public ServerResponse selectFoodsListByFoodsTypeId(Integer pageNum,Integer pageSize,Integer foodsTypeId){
		PageHelper.startPage(pageNum,pageSize);
		//只查询所有上架的商品
		List<Foods> list = foodsMapper.selectFoodsByFoodsTypeId(foodsTypeId,Const.FoodsStatus.FOODS_SHANGJIA);
		if(list.size()==0){
			return ServerResponse.createByErrorMessage("当前分类没有菜品");
		}
		PageInfo pageInfo = new PageInfo(list);
		return ServerResponse.createBySuccess(pageInfo);
	}

}
